//
//  ReadPageView_Scrawl.m
//  KidReading
//
//  Created by telen on 16/4/26.
//  Copyright © 2016年 刘赞黄Telen. All rights reserved.
//

#import "ReadPageView_Scrawl.h"
#import "ConstDefine.h"

@implementation ReadPageView_Scrawl
{
    TLPaintView* paintView;
}

- (void)setColor:(UIColor *)color{paintView.paintModel.color = color;}
- (UIColor*)color{return paintView.paintModel.color;}

- (void)setLineWidth:(CGFloat)lineWidth{paintView.paintModel.lineWidth = lineWidth;}
- (CGFloat)lineWidth{return paintView.paintModel.lineWidth;}

//- (void)setIsEarser:(BOOL)isEarser{paintView.isClickedToDelModel = isEarser;}
//- (BOOL)isEarser{return paintView.isClickedToDelModel;}
- (void)setIsEarser:(BOOL)isEarser{paintView.isEarser = isEarser;}
- (BOOL)isEarser{return paintView.isEarser;}

- (void)setDrawLineRatio:(CGFloat)drawLineRatio{paintView.drawLineRatio = drawLineRatio;}
- (CGFloat)drawLineRatio{return paintView.drawLineRatio;}

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        //
        _modyPaintModelList = [NSMutableArray new];
        _delPaintModelList = [NSMutableArray new];
        _syncPaintModelList = nil;
        //
        paintView = [[TLPaintView alloc] initWithFrame:self.bounds];
        paintView.backgroundColor = [UIColor clearColor];
        [paintView initPaintView];
        [self addSubview:paintView];
        //
        __weak ReadPageView_Scrawl * wself = self;
        paintView.didAddPaintModel = ^(TLPaintModel* paintModel){
            [wself didAddPaintModel:paintModel];
        };
    }
    return self;
}

- (void)setEditModel:(BOOL)editModel
{
    [super setEditModel:editModel];
    if (paintView.superview) {
        [paintView removeFromSuperview];
        if (editModel && self.rootView) {
            [self.rootView addSubview:paintView];
        }else{
            [self addSubview:paintView];
        }
    }
}

#pragma mark-
- (void)didAddPaintModel:(TLPaintModel*) paintModel
{
    [_modyPaintModelList addObject:paintModel];
}

#pragma mark-
- (void)clearAndDeletePaints
{
    [_delPaintModelList addObjectsFromArray:_syncPaintModelList];
    [_delPaintModelList addObjectsFromArray:_modyPaintModelList];
    [_modyPaintModelList removeAllObjects];
    [paintView clear];
}

- (void)clearOnlyDisplyPaints
{
    [paintView clear];
}

- (void)paints_syncList:(NSArray<TLPaintModel *> *)list
{
    _syncPaintModelList = list;
    [paintView paintModelList:list];
    [paintView paintModelList:_modyPaintModelList];
}

@end
